#pragma once


#include <IXHwnd.h>
#include "XFrameImpl.h"


template <class I>
class CXHwndImpl : public CXFrameImpl<I>
{
    typedef CXFrameImpl<I> superclass;

    BEGIN_DEF_SKIN_CLASS(CXHwnd, superclass, gs_strGuidXSkin)
        IMP_BASIC_INTF(IXHwnd,    0)
    END_DEF_SKIN_CLASS();

    IMPL_CONTROL_OBJ(CXHwndImpl, superclass, _T("Hwnd"));

public:
    CXHwndImpl();
    virtual ~CXHwndImpl();

public:
    // IXControl
    virtual HRESULT STDMETHODCALLTYPE   Create(IXControl* pParent, RECT* prcWnd, LPCTSTR szId);
    virtual HRESULT STDMETHODCALLTYPE   put_Text(IN LPCTSTR szText);
    virtual HRESULT STDMETHODCALLTYPE   get_Text(IN BSTR* bstrText);
    virtual void    STDMETHODCALLTYPE   Invalidate();
    virtual void    STDMETHODCALLTYPE   Invalidate(RECT* pRect);

public:
    // IXHwnd
    virtual void    STDMETHODCALLTYPE   Attach(IXControl* pParent, XWND xWnd, LPCTSTR szId);
    virtual void    STDMETHODCALLTYPE   Detach();
    virtual XWND    STDMETHODCALLTYPE   GetHandle();
    virtual DWORD   STDMETHODCALLTYPE   GetHwndFlags();

    virtual DWORD   STDMETHODCALLTYPE   GetStyle();
    virtual void    STDMETHODCALLTYPE   ModifyStyle(DWORD dwAddStyle, DWORD dwRemoveStyle);

    virtual DWORD   STDMETHODCALLTYPE   GetExtendStyle();
    virtual void    STDMETHODCALLTYPE   ModifyExtendStyle(DWORD dwAddExStyle, DWORD dwRemoveExStyle);

    virtual BOOL    STDMETHODCALLTYPE   OnCommand(UINT command);
    virtual BOOL    STDMETHODCALLTYPE   OnCtlColor(XCANVAS xCanvas, OUT XBRUSH* pBrush);
    virtual void    STDMETHODCALLTYPE   SetBackBrush(IN XBRUSH bkBrush);

    virtual LRESULT STDMETHODCALLTYPE   OnHwndWndProc(UINT message, WPARAM wParam, LPARAM lParam, BOOL* bHandled);

public:
    // IXBaseObj
    virtual void STDMETHODCALLTYPE   OnFinalRelease();

protected:
    // CXControlImpl<I>
    virtual void OnControlFlagsChanged(eSkinControlFlags flag, BOOL bAdd);
    virtual void OnSizeChanged();
    virtual void OnPosChanged();

protected:
    void    DetachImpl(BOOL bDestroy);
    void    CreateRealWindow(XWND xParentWnd, RECT* prcWnd);

    // CXHwndImpl Callback
    virtual HWND    OnCreateRealWindow(XWND xParentWnd, RECT* prcWnd);
    virtual XString GetHwndClassName();
    virtual void    OnAttached();
    virtual void    OnDetached();

protected:
    static LRESULT WINAPI xHwndWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

protected:
    XWND        m_xRealWnd;
    DWORD       m_dwStyle;
    DWORD       m_dwExtendStyle;
    WNDPROC     m_PrevWndProc;
    XBRUSH      m_BkBrush;
};


class CXHwnd : public CXHwndImpl<IXHwnd>
{
};
